<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.school.platform.servlet.InfoListServlet.Info" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>信息列表</title>
    <style>
        /* 全局样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: url('https://tse1-mm.cn.bing.net/th/id/OIP-C.62ldstqXOT3z4aLkucEuSgHaE8?w=277&h=185&c=7&r=0&o=5&dpr=1.3&pid=1.7') no-repeat center center fixed;
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            margin: 0;
            padding: 50px 0;
        }

        .container {
            width: 90%;
            max-width: 1000px;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.92);
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
        }

        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
            font-size: 28px;
        }

        form.search {
            text-align: center;
            margin-bottom: 30px;
        }

        input[type="text"] {
            width: 300px;
            padding: 14px;
            border: 1px solid #bdc3c7;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s ease;
            margin-right: 10px;
        }

        input[type="text"]:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 8px rgba(52, 152, 219, 0.3);
        }

        input[type="submit"] {
            background-color: #3498db;
            color: #ffffff;
            padding: 14px 25px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        input[type="submit"]:hover {
            background-color: #2980b9;
        }

        ul {
            list-style-type: none;
            padding: 0;
        }

        li {
            background-color: #ffffff;
            padding: 25px;
            margin-bottom: 25px;
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
        }

        li:hover {
            transform: translateY(-5px);
        }

        h2 {
            margin-top: 0;
            color: #34495e;
            font-size: 22px;
            margin-bottom: 10px;
        }

        p {
            margin: 8px 0;
            color: #7f8c8d;
            font-size: 16px;
        }

        a {
            color: #3498db;
            text-decoration: none;
            font-size: 16px;
            transition: color 0.3s ease;
        }

        a:hover {
            color: #2980b9;
            text-decoration: underline;
        }

        .action-link {
            text-align: center;
            margin-top: 30px;
        }

        .no-results {
            text-align: center;
            color: #e7de3c;
            font-size: 18px;
            margin-top: 20px;
        }
    </style>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const searchInput = document.querySelector('input[name="keyword"]');
            searchInput.addEventListener('keydown', function(event) {
                if (event.key === 'Enter') {
                    event.preventDefault();
                    document.querySelector('form.search').submit();
                }
            });
        });
    </script>
</head>
<body>
<div class="container">
    <h1>信息列表</h1>
    <form class="search" action="infoList" method="get">
        <!-- 回显搜索关键字 -->
        <input type="text" name="keyword" placeholder="搜索关键词" value="<%= request.getParameter("keyword") != null ? request.getParameter("keyword") : "" %>">
        <input type="submit" value="搜索">
    </form>
    <ul>
        <% List<Info> infoList = (List<Info>) request.getAttribute("infoList");
            if (infoList != null && !infoList.isEmpty()) {
                for (Info info : infoList) { %>
        <li>
            <h2><%= info.getTitle() %></h2>
            <p>发布者：<%= info.getUsername() %>，发布时间：<%= info.getCreateTime() %></p>
            <p><%= info.getContent() %></p>
            <!-- 原链接错误：直接链接到infoDetail.jsp，现改为指向InfoDetailServlet -->
            <a href="infoDetail?infoId=<%= info.getId() %>">查看详情</a>
        </li>
        <% }
        } else { %>
        <li class="no-results">没有找到相关信息。</li>
        <% } %>
    </ul>
    <div class="action-link">
        <% if (session.getAttribute("username") != null) { %>
        <a href="publishInfo.jsp">发布信息</a>
        <% } else { %>
        <a href="login.jsp">登录发布信息</a>
        <% } %>
    </div>
</div>
</body>
</html>